package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.ContractUserEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/25 10:18
 * @since v1.0
 */
public interface ContractUserModel extends IModel<ContractUserEntity> {

    /**
     * 获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return java.util.List<com.xbongbong.saas.domain.entity.CustomerUserEntity>
     * @author feng.zheng
     * @date 2019/2/16 14:22
     */
    @Override
    List<ContractUserEntity> findEntitys(Map<String, Object> param);

    /**
     * 保存实体
     *
     * @param contractUserEntity 客户协同人团队实体
     * @return java.lang.Integer
     * @throws XbbException 数据库异常
     * @author feng.zheng
     * @date 2019/2/14 16:42
     */
    Integer save(ContractUserEntity contractUserEntity) throws XbbException;

    /**
     * 获取单个实体
     *
     * @param key    id主键
     * @param corpid 公司id
     * @return com.xbongbong.saas.domain.entity.ContractUserEntity
     * @author feng.zheng
     * @date 2019/2/14 16:43
     */
    ContractUserEntity getByKey(Long key, String corpid);


    /**
     * 删除某公司某合同对应的销售团队
     *
     * @param corpid     公司ID
     * @param contractId 合同ID
     * @return 0失败，1成功
     * @author kaka
     * @date 2018-01-04
     */

    /**
     * Description: 获取合同负责人或协同人id list
     * @param corpid 公司id
     * @param contractId 合同id
     * @param isMain 是否为负责人 1负责人 0 协同人
     * @return java.util.List<java.lang.String>
     * @author 魏荣杰
     * @date 2019/2/20 17:15
     * @since v1.0
     */
    List<String> getContractUserIdList(String corpid, Long contractId, Integer isMain);
    /**
     * Description: 获取合同负责人或协同人 list
     * @param corpid 公司id
     * @param contractId 合同id
     * @param isMain 是否为负责人 1负责人 0 协同人
     * @return java.util.List<java.lang.String>
     * @author 吴峰
     * @date 2021-07-26 09:37
     * @since v1.0
     */
    List<ContractUserEntity> getContractUserList(String corpid, Long contractId, Integer isMain);
    /**
     * Description:批量获取合同负责人或协同人id
     * @param corpid 公司id
     * @param contractIds 合同ids
     * @param isMain 是否为负责人 1负责人 0 协同人
     * @return java.util.List<java.lang.String>
     * @author 魏荣杰
     * @date 2019/2/20 17:13
     * @since v1.0
     */
    List<String> getContractUserIdList(String corpid, List<String> contractIds, Integer isMain);


    /**
     * 批量解散团队依据客户id
     * @param corpid
     * @param customerIdList
     */
    void disbandedTeamByCustomerId(String corpid, List<Long> customerIdList) throws XbbException;

    /**
     * 删除合同团队
     * @param contractUser
     */
    void delete(ContractUserEntity contractUser) throws XbbException;

    /**
     * 插入合同协同团队
     * @param userEntity
     * @param contractId
     * @param isMain
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-23 18:22
     */
    void contractUserInsert(UserEntity userEntity, Long contractId, Integer isMain) throws XbbException;

    /**
     * 查询协同团队基础列表
     * @param map 参数
     * @return 团队
     */
    List<UserTeamEntity> findBaseEntitys(Map<String,Object> map);

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/3/13 16:20
     * @param contractIdIn 合同id
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer deleteByContractIdIn(List<Long> contractIdIn, String corpid) throws XbbException;
    /**
     * 获取协同团队的业务数据
     * @param corpid 公司id
     * @param isMain 负责或协同
     * @param userId 用户id
     * @return List<Long>
     * @author long.rao
     * @date 2019-03-20 15:34
     */
    List<Long> getDataIdList(String corpid, Integer isMain, List<String> userId);

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量插入
     * @param insertBatchList
     */
    void insertBatch(List<ContractUserEntity> insertBatchList, boolean isImport) throws XbbException;


    /**
     * 通过userId,contractId获取实体
     * @param corpid 公司id
     * @param userId 员工userId
     * @param contractId 合同id
     * @return 合同销售团队记录
     */
    ContractUserEntity getByUserIdContractId(String corpid, String userId, Integer contractId);

    /**
     * 批量更新
     * @param contractUserEntityList
     * @param corpid
     * @param del
     * @throws XbbException
     */
    void deleteBatchUser(List<ContractUserEntity> contractUserEntityList, String corpid, Integer del) throws XbbException;

    Integer deleteBatch(List<Long> list, String corpid) throws XbbException;

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del) throws XbbException;

    void updateBatchCustomerId(List<ContractUserEntity> contractUserEntityList, String corpid) throws XbbException;

    /**
     * 批量剔除团队
     * @param corpid
     * @param removeIdList 客户团队表idList
     */
    Map<Long, String> batchDeleteById(String corpid, List<Long> removeIdList) throws XbbException;

    /**
     * 批量更新
     * @param list
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer updateBatch(List<ContractUserEntity> list, String corpid) throws XbbException;

    /**
     * 编辑团队成员标签
     *
     * @param contractUserEntity
     */
    void editLabel(ContractUserEntity contractUserEntity) throws XbbException;

    /**
     * 更新协同人可编辑权限
     *
     * @param shouldUpdateEntity
     */
    void updateEditFormPer(ContractUserEntity shouldUpdateEntity) throws XbbException;

    /**
     * 更新团队协同人信息和协同人可编辑权限
     *
     * @param corpid
     * @param idIn
     * @param updateUserToCoTeamList
     * @param coopUser
     * @param needThrow
     */
    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserToCoTeamList, Integer coopUser, boolean needThrow) throws XbbException;

    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, boolean needThrow, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;
}
